package Games;

import Client.CpuComm;

public class ComputerPlayer  {
	
	public static CpuComm comm;
	private String serverIp = "localhost";
	private int port = 7789;
	public static GameInterface ComputerAi;
	
	public ComputerPlayer(String computerPlayer, GamesModel gamesModel){
		comm = new CpuComm();
		Connnect();
		login(computerPlayer);
		subscribe(gamesModel.getSelectedGame());
		if(gamesModel.getSelectedGame() == "TicTacToe"){
			ComputerAi = new TicTacToeComputerAi(GamesController.gamesModel(), comm);
		}else if(gamesModel.getSelectedGame() == "Othello"){
			ComputerAi = new OthelloComputerAi(GamesController.gamesModel(), comm);
		}
	}
	
	private void Connnect(){
		if(comm.connect(serverIp,port)) {
			System.out.println("CPU connected");
		}
	}
	
	private void login(String computerPlayer){
		comm.send("login "+computerPlayer);
	}
	
	private void subscribe(String game){
		comm.send("subscribe " + game);
	}
}
